package com.hongyuan.sellfitness.ui.find.view_mode;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.hongyuan.mvvmhabitx.binding.command.BindingAction;
import com.hongyuan.mvvmhabitx.binding.command.BindingCommand;
import com.hongyuan.sellfitness.base.Constants;
import com.hongyuan.sellfitness.base.ItemViewModel;
import com.hongyuan.sellfitness.ui.find.beans.CirclePeopleBean;
import com.hongyuan.sellfitness.ui.person.activity.UserInfoActivity;

public class CirclePeopleItemViewModel extends ItemViewModel<CirclePeopleViewModel> {

    public ObservableField<CirclePeopleBean.ListBean> entity = new ObservableField<>();

    public CirclePeopleItemViewModel(@NonNull CirclePeopleViewModel viewModel, CirclePeopleBean.ListBean bean) {
        super(viewModel);
        entity.set(bean);
    }

    //条目的点击事件
    public BindingCommand itemClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            Bundle bundle = new Bundle();
            bundle.putString("user_id",String.valueOf(entity.get().getM_id()));
            bundle.putString("userPhone",entity.get().getM_mobile());
            viewModel.startActivity(UserInfoActivity.class,bundle);
        }
    });

    //关注ta
    public BindingCommand attention = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            //设置要操作的对象
            viewModel.itemClick(CirclePeopleItemViewModel.this);
            if(entity.get().getIs_friend() != 1){

                //关注
                viewModel.setParams("f_mid",String.valueOf(entity.get().getM_id())).setParams("f_type","add");
                viewModel.requestData(Constants.ADD_FRIENT);

            }else{
                //取消关注
                viewModel.setParams("f_mid",String.valueOf(entity.get().getM_id())).setParams("f_type","reduce");

                //弹框提示是否需要操作
                viewModel.uc.showCancel.call();

            }
        }
    });
}
